import { transPx } from "../../utils/util"

// 获取应用实例
Component({
  properties: {
		title: {
			type: String,
			value: ''
		},
    isFixed: {
      type: Boolean,
      value: false
    },
    isBlock: {
      type: Boolean,
      value: false
    },
    isBack: {
      type: Boolean,
      value: true
    },
	},
  data: {
    navHeight: 0,
    pagesLength: 1,
    buttonWidth: 0,
    navWidth: 0
  },
  ready() {
    const MenuButtonBoundingClientRect = getApp<IAppOption>().globalData.MenuButtonBoundingClientRect
    const statusHeight = getApp<IAppOption>().globalData.statusHeight
    const navHeight =  MenuButtonBoundingClientRect.height + (MenuButtonBoundingClientRect.top - statusHeight) * 2

    const buttonWidth = MenuButtonBoundingClientRect.width - transPx(40)
    const navWidth = wx.getSystemInfoSync().windowWidth - (2*buttonWidth) - transPx(80)
    const pagesLength = getCurrentPages().length
    this.setData({navHeight, pagesLength, buttonWidth, navWidth})
  },
  // 返回上页
  methods: {
    toBack() {
      if (!this.data.isBack) return
      if (this.data.pagesLength > 1) {
        wx.navigateBack()
      } else {
        wx.reLaunch({
           url: '/pages/index/index'
        })
      }
    }
  } 
})